<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #rong {
            width: 400px;
            height: 400px;
            margin: 100px auto;
            position: relative;
        }
        
        img {
            width: 400px;
            height: 400px;
            position: absolute;
            opacity: 0;
            transition: all 1s;
        }
        
        img:first-child {
            opacity: 1;
        }
        
        li:first-child {
            background-color: rgb(47, 0, 255);
        }
        
        ul {
            width: 100px;
            height: 10px;
            display: flex;
            /* background-color: rgb(248, 132, 132); */
            position: absolute;
            justify-content: space-between;
            bottom: 10px;
        }
        
        li {
            list-style: none;
            width: 10px;
            height: 10px;
            /* position:ab; */
            background-color: rgb(119, 0, 216);
            /* background-color: rgb(47, 0, 255); */
            border-radius: 50%;
            /* opacity: 0; */
        }
    </style>
</head>

<body>
    <div id="rong">

        <img src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3378708182,3822632179&fm=26&gp=0.jpg" alt="">
        <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2082848815,1382311806&fm=26&gp=0.jpg" alt="">
        <img src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1462597699,2457940300&fm=26&gp=0.jpg" alt="">
        <img src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=264986648,3480936303&fm=26&gp=0.jpg" alt="">
        <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=196373800,1078086604&fm=11&gp=0.jpg" alt="">
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
</body>

</html>
<script>
    var img = document.getElementsByTagName('img');
    var li = document.getElementsByTagName('li');
    console.log(li);
    console.log(img);
    var a;
    var k = 0;
    var b = 0;
    for (var i = 0; i < img.length; i++) {
        li[i].onclick = function() {
            for (var j = 0; j < img.length; j++) {
                if (this == li[j]) {
                    a = j;
                    console.log(j);
                    b = a;
                }
            }

            for (k = 0; k < li.length; k++) {
                if (a == k) {
                    img[k].style.opacity = 1;
                    li[k].style.backgroundColor = 'rgb(47, 0, 255)';
                } else {
                    img[k].style.opacity = 0;
                    li[k].style.backgroundColor = 'rgb(119, 0, 216)';
                }
            }
        }
    }

    setInterval(function() {

        img[b].style.opacity = 0;
        li[b].style.backgroundColor = 'rgb(119, 0, 216)';


        b++;
        if (b >= 5) {
            b = 0
        }
        img[b].style.opacity = 1;
        // li[b].style.opacity = 0;
        li[b].style.backgroundColor = 'rgb(47, 0, 255)';



    }, 2000)
</script>